package test.orm;


import java.util.List;

import org.apache.ibatis.session.SqlSession;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import zdy.web.orm.mybatis2.pojo.*;
import zdy.web.orm.mybatis2.mybatisFactory;

/*
 * 第二种写法
 * */

public class temybatis2 {

	@Before
	public void setUp() throws Exception {
	}

	@After
	public void tearDown() throws Exception {
	}
    private final String classname="zdy.web.orm.mybatis2.mapp.GoodsMapper.";
	@Test
	public void selectone() {
		SqlSession sqlSession = mybatisFactory.getSqlSession();
	
		int id = 1;
		Goods cur =sqlSession.selectOne(classname+"selectOne",id);
		try {  
			if (cur != null) {
			System.out.println("title:" + cur.getTitle());
		} 
		} finally {  
			sqlSession.close();  
	    }  
	}
	
	@Test
	public void selectRecommendGoods() {
		SqlSession sqlSession = mybatisFactory.getSqlSession();	
		String name = "x";
		List<Goods> lis = sqlSession.selectList(classname+"selectRecommendGoods",name); 
		if (!lis.isEmpty()) {
			System.out.println("selectsByName begin:");
			for (Goods cur : lis) {
				System.out.println( cur.getTitle());
			}
			System.out.println("selectsByName end:");
		}
	}
	@Test
	public void selectAll() {
		SqlSession sqlSession = mybatisFactory.getSqlSession();	
		String name = "x";
		List<Goods> lis = sqlSession.selectList(classname+"selectAll"); 
		if (!lis.isEmpty()) {
			System.out.println("selectsByName begin:");
			for (Goods cur : lis) {
				System.out.println( cur.getTitle());
			}
			System.out.println("selectsByName end:");
		}
	}


}
